package com.demo.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;

import com.demo.adapter.TextAdapter;
import com.demo.model.TextModel;
import com.demo.widget.NLongListView;
import com.demo.widget.NLongListView.DataListener;
import com.example.androiddemo.R;

public class TextActivity extends Activity {

	private List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
	private NLongListView longListView;
	private TextAdapter textAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_text);

		initData();
		initView();
		bindListener();

	}

	private void bindListener() {
		longListView.setDataListener(new DataListener() {

			@Override
			public void getOldData() {
				initData();
			}

			@Override
			public void getNewData() {
				// TODO Auto-generated method stub

			}
		});
	}

	private void initView() {
		
		longListView = (NLongListView) findViewById(R.id.textLongListView);

		textAdapter = new TextAdapter(TextActivity.this, data, R.layout.item_text, new String[] { "header", "content" }, new int[] { R.id.headerText, R.id.contentText });
		
		longListView.setColumnCount(1);
		longListView.setAdapter(textAdapter);
		
	}

	private void initData() {
		
		List<TextModel> newTextModels = new ArrayList<TextModel>();
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));
		newTextModels.add(new TextModel("header", "my content description!"));

		for (TextModel textModel : newTextModels) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("header", textModel.getHeader());
			map.put("content", textModel.getContent());
			data.add(map);
		}
	}
}
